package com.whu.waterworks.model;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;


public class MyUserDetails implements UserDetails {
	/**
	 * 
	 */
	private static final long serialVersionUID = 503792885550162563L;
	private String username;
	private String password;
	private String permission;
	private String role;
	private String type;
	private String area;
	private Set<MyGrantedAuthority> grantedAuthoritySet;
	
	public MyUserDetails(String username, String password, String permission,
			String type, String area) {
		super();
		this.username = username;
		this.password = password;
		this.permission = permission;
		this.role = permission;
		this.type = type;
		this.area = area;
	}
	public MyUserDetails(WaterUser waterUser) {
		super();
		this.username = waterUser.getUsername();
		this.password = waterUser.getPassword();
		this.permission = waterUser.getPermission();
		this.role = waterUser.getPermission();
		this.type = waterUser.getType();
		this.area =waterUser.getArea() ;
		grantedAuthoritySet =new HashSet<>();
		grantedAuthoritySet.add(new MyGrantedAuthority(role));
	}
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		if(grantedAuthoritySet.isEmpty())
		{
			System.out.println("empty-----");
		}
		for(GrantedAuthority s:grantedAuthoritySet)
		{
			System.out.println("test:"+((MyGrantedAuthority)s).getAuthority());
		}
		return grantedAuthoritySet;
	}
	
	@Override
	public String getPassword() {
		return password;
	}
	@Override
	public String getUsername() {
		// TODO Auto-generated method stub
		return username;
	}
	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}
	public String getPermission() {
		return permission;
	}
	public void setPermission(String permission) {
		this.permission = permission;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getArea() {
		return area;
	}
	public void setArea(String area) {
		this.area = area;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}

}
